<template>
	<view>
		<!-- :mid-button="true" -->
		<u-tabbar v-model="current" :list="list" @change="onTabBarChange" :mid-button-size="40" :fixed="true"
			active-color="#585CF9" :placeholder="true" :safeAreaInsetBottom="false" text-size="14rpx" icon-size="30rpx"
			:text-color="''">
		</u-tabbar>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	const app = getApp();
	export default {
		name: "tabBar",
		props: {
			current: Number,
			IsTabDot: Number
		},
		data() {
			return {
				list: [{
						text: "首页",
						pagePath: "/pages/index/index",
						iconPath: "https://www.wytldy.com/file/wxIMG/tabbar/home.png",
						selectedIconPath: "https://www.wytldy.com/file/wxIMG/tabbar/home_act.png",

					},
					{
						text: "课程中心",
						pagePath: "/pages/Course/Course",
						iconPath: "https://www.wytldy.com/file/wxIMG/tabbar/course.png",
						selectedIconPath: "https://www.wytldy.com/file/wxIMG/tabbar/course_act.png",
					},
					{
						text: "实践任务",
						pagePath: "/pages/PracticalTasks/PracticalTasks",
						iconPath: "https://www.wytldy.com/file/wxIMG/tabbar/practical_tasks.png",
						selectedIconPath: "https://www.wytldy.com/file/wxIMG/tabbar/practical_tasks_act.png",
						midButton: true,
					},
					{
						text: "班级风采",
						pagePath: "/pages/ClassStyle/ClassStyle",
						iconPath: "https://www.wytldy.com/file/wxIMG/tabbar/class_style.png",
						selectedIconPath: "https://www.wytldy.com/file/wxIMG/tabbar/class_style_act.png",
					},
					{
						text: "我的",
						pagePath: "/pages/MyInfo/MyInfo",
						iconPath: "https://www.wytldy.com/file/wxIMG/tabbar/my.png",
						selectedIconPath: "https://www.wytldy.com/file/wxIMG/tabbar/my_act.png",
					},
				],
				role: uni.getStorageSync('role'),
				user: uni.getStorageSync('user'),
				clazz: uni.getStorageSync('clazz')
			};
		},
		mounted() {

			if (uni.getStorageSync('token') != '') {
				if (this.role == `stu`) {
					this.getStuClass()
					this.list[2].pagePath = "/pages/StudentPracticalTasks/StudentPracticalTasks"
					this.list[3].pagePath = "/pages/StudentClassStyle/StudentClassStyle"
				} else if (this.role == `tr`) {
					this.list[2].pagePath = "/pages/TeacherePracticalTasks/TeacherePracticalTasks"
					this.list[3].pagePath = "/pages/TeacherClassStyle/TeacherClassStyle"
					this.getTeacherClassList()
				}

			}
		},
		methods: {
			onTabBarChange(name) {
				uni.reLaunch({
					url: this.list[name].pagePath
				})
			},
			getStuClass() {
				let opts = {
					url: '/dclass/getStuClass',
					method: 'post'
				};
				let params = {
					userid: this.user.id
				};
				this.$api.post(opts, params).then(res => {
					this.bjmc = res.data.bjmc;
					uni.setStorageSync('dclass', res.data);
				})
			},
			getTeacherClassList() {
				if (this.clazz) {
					console.log(222)
				} else {
					this.$api.post({
						url: '/dclass/trClassList'
					}, {
						trid: this.user.id
					}).then(res => {
						console.log(res)
						if (res.list.length > 0) {
							uni.setStorageSync("clazz", res.list[0])
						}

					})
				}

			},
		}
	}
</script>

<style lang="scss">
	.u-page__item__slot-icon {
		width: 60rpx;
		height: 60rpx;
	}

	/* 选中状态下的字体颜色 */
	// .u-tabbar .u-tabbar-item.selected .u-tabbar-text  {
	// 	color: #007AFF !important;
	// }

	/* 非选中状态下的字体颜色 */
	// .u-tabbar .u-tabbar-item:not(.selected) .u-tabbar-text {
	// 	color: #999999 !important;
	// }
</style>